package test;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;


public class ThroughputRecord {
	
	String record;
	
	public void cal(String s, ArrayList<HashMap<String,String>> tokenPool){
		ArrayList<Integer> idList = new ArrayList<Integer>();
		ArrayList<Double> valueList = new ArrayList<Double>();
		System.out.println("tokenPool size: " + tokenPool.size());
		for(HashMap<String,String> token: tokenPool){
			if(token.get("$pBId").equals("5")){
				idList.add(Integer.parseInt(token.get("$pId")));
				valueList.add(Double.parseDouble(token.get("$pATime")));
			}
		}
		System.out.println("record size: " + idList.size());
		
		File log = new File("throughput");
		if (!log.exists())
			log.mkdir();
		String fileName = s + new SimpleDateFormat("@[yyyy-MM-dd] HH-mm-ss")
				.format(new Date());
		try {
			FileOutputStream fos = new FileOutputStream("throughput/" + fileName
					+ ".txt");
			
			PrintStream ps = new PrintStream(fos);
			String id="{";
			String values="{";
			for(int i: idList){
				id += i + ",";
			}
			id=id.substring(0,id.length()-1);
			id+="};";
			ps.println(id);
			
			for(double d: valueList){
				values += d + ",";
			}
			values=values.substring(0,values.length()-1);
			values+="};";
			ps.println(values);
			
			ps.close();
			
			fos.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
}
